<template>
  <div class="app-main-container">
    <!-- <div class="app-main-title">门票订单</div> -->
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <div v-if="meta.indexOf('BraceletDepositList') > -1" class="doumee_table_header">
      <el-button
        type="primary"
        @click="showPzbtn"
      >押金配置</el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table doumee-element-tableb"
    >
      <el-table-column
        align="center"
        label="手环ID"
        prop="braceletId"
        min-width="130"
        show-overflow-tooltip
      />
      <el-table-column label="会员信息" min-width="250" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.userName || '' }}
          {{ scope.row.phone ? '-' : '' }}
          {{ scope.row.phone || '' }}
          {{ scope.row.number ? '-' : '' }}
          {{ scope.row.number || '' }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="关联类型"
        min-width="100"
        prop="userType"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            scope.row.userType === '0'
              ? '会员'
              : scope.row.userType === '1'
                ? '散客'
                : ''
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="押金支付方式"
        prop="payMethod"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        prop="realDeposit"
        label="支付押金"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="退还押金"
        prop="tkDeposit"
        min-width="80"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        prop="billBusinessId"
        label="票据票号"
        min-width="210"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="票据名称"
        prop="billName"
        min-width="120"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="绑定时间"
        prop="createTime"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="解绑时间"
        prop="unbindTime"
        min-width="160"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="状态"
        min-width="100"
        fixed="right"
        prop="status"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{
            scope.row.status == 0
              ? '已解绑'
              : scope.row.status == 1
                ? '已绑定'
                : ''
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        min-width="150"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status == 1 && meta.indexOf('RefundBraceletOrder') > -1"
            v-preventReClick
            type="text"
            @click="jbBtn(scope.row)"
          >解绑</el-button>
          <el-button
            v-if="scope.row.billOrderId && scope.row.isRefund === '1'"
            v-preventReClick
            type="text"
            @click="print(scope.row.billOrderId, 'BRACELET_REFUND_TPML')"
          >打印</el-button>
          <el-button
            v-if="scope.row.billOrderId && scope.row.isRefund === '0'"
            v-preventReClick
            type="text"
            @click="print(scope.row.billOrderId, 'BRACELET_TPML')"
          >打印</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Paginations
      :total="total"
      :page="pagination.page"
      @SizeChange="pageSizeChange"
      @current-change="getList"
    />
    <Deposit ref="Deposit" @add="depositAdd" @edit="depositEdit" />
    <DepositEdit ref="DepositEdit" />
    <Unbinding ref="Unbinding" @success="getList(1)" />
  </div>
</template>

<script>
import {
  getBraceletOrderList, printOrder
} from '@/api'
import { parseTime } from '@/utils'
import Paginations from '@/components/paginations/paginations'
import QueryForm from '@/components/QueryForm'
import { queryFormConfig } from './config'
import Deposit from './components/deposit.vue'
import DepositEdit from './components/depositEdit.vue'
import Unbinding from './components/unbinding.vue'
export default {
  name: 'AssociationList',
  components: {
    QueryForm,
    Deposit,
    Unbinding,
    DepositEdit,
    Paginations
  },
  data() {
    return {
      queryFormConfig,
      meta: [],
      list: [],
      total: 0,
      pagination: {
        page: 1,
        rows: 10
      },
      listLoading: true,
      billOrderId: '',
      filters: {}
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList(1)
  },
  methods: {
    pageSizeChange(val) {
      this.pagination.rows = val
      this.getList(1)
    },
    showPzbtn() {
      this.$refs.Deposit.getList(1)
    },
    depositAdd() {
      this.$refs.DepositEdit.show()
    },
    print(workId, templateCode) {
      printOrder({
        param: {
          contentMap: {},
          venueId: sessionStorage.getItem('venueId'),
          workId,
          templateCode
        }
      })
        .then((res) => {
          console.log(res)
        })
        .catch((err) => {
          console.log(err)
        })
    },
    depositEdit(e) {
      this.$refs.DepositEdit.show(e)
    },
    jbBtn(e) {
      this.billOrderId = e.billOrderId
      this.$refs.Unbinding.show(e)
    },
    // 清空
    clear() {
      this.filters = {}
      this.getList(1)
    },
    getList(page) {
      const { filters, pagination } = this
      if (page) {
        pagination.page = page
        this.pagination.page = Number(page)
      }
      pagination.firstQueryTime = parseTime(new Date())
      if (filters.time) {
        filters.startTime = filters.time[0]
        filters.endTime = filters.time[1]
      } else {
        filters.startTime = ''
        filters.endTime = ''
      }
      this.listLoading = true
      getBraceletOrderList({ pagination, param: {
        ...filters,
        venueId: sessionStorage.getItem('venueId')
      }}).then(res => {
        this.listLoading = false
        if (res.errorCode === '000000') {
          this.list = res.recordList
          this.total = res.totalCount
        }
      }).catch(() => {
        this.listLoading = false
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.vip-info {
  display: flex;
  justify-content: center;
  .name-phone {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
    margin-left: 10px;
    flex: 1;
  }
}
</style>
